package com.ruoyi.web.controller.pay;

import org.yaml.snakeyaml.Yaml;

import java.io.InputStream;
import java.util.Map;
/**
 * This file is part of 南阳迈特网络科技有限公司.
 * @company  南阳迈特网络科技有限公司
 * @link     https://www.nymaite.com
 * @document https://product.nymaite.cn
 * @contact  service@nymaite.com
 * @author nymaite
 */
public class PayPalPaymentConfig {

    private static String paypalSuccessPage;
    private static String paypalCancelPage;

    static {
        loadConfig();
    }

    private static void loadConfig() {
        Yaml yaml = new Yaml();
        try (InputStream inputStream = PayPalPaymentConfig.class.getClassLoader().getResourceAsStream("application.yml")) {
            Map<String, Object> config = yaml.load(inputStream);
//            paypalCancelPage = config.get("pay");
            Map<String, Object> payConfig = (Map<String, Object>) config.get("pay");
            Map<String, String> paypalConfig = (Map<String, String>) payConfig.get("paypal");
            paypalSuccessPage = paypalConfig.get("PAYPAL_SUCCESS_PAGE");
            paypalCancelPage = paypalConfig.get("PAYPAL_CANCEL_PAGE");

        } catch (Exception e) {
            e.printStackTrace();
            // 可以在出现异常时进行适当处理，比如使用默认值
        }
    }

    public static String getPaypalSuccessPage() {
        return paypalSuccessPage;
    }

    public static String getPaypalCancelPage() {
        return paypalCancelPage;
    }

    public static void updateConfig(String successPage, String cancelPage) {
        paypalSuccessPage = successPage;
        paypalCancelPage = cancelPage;
    }

}
